package treepro;

import java.util.ArrayList;
import java.util.EventObject;

/**
 *
 * @author Ivan
 */
public class ChangeEvent extends EventObject {

    private ArrayList<ChangeListener> listeners = new ArrayList<ChangeListener>();
    
    public ChangeEvent(Object source) {
        super(source);
    }
    
    public void addChangeListener(ChangeListener listener) {
        listeners.add(listener);
    }
    
    public ChangeListener[] getChangeListeners() {
        return listeners.toArray(new ChangeListener[listeners.size()]);
    }
    
    public void removechangeListener(ChangeListener listener) {
        listeners.remove(listener);
    }
    
    protected void fireChangeEvent() {
        ChangeEvent evt = new ChangeEvent(this);
        for (ChangeListener listener:listeners) {
            listener.onChange(evt);
        }
    }
    
}
